<template>
  <div>
    <div class="werapp">
      <h1>品类管理--添加品类</h1>
    </div>
    <div class="box-item">
      <p>
        <b>所有品类：</b>
        <el-select v-model="model.id" placeholder="/所有">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="'/所有/'+item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </p>
      <p>
        <b>品类名称：</b>
        <el-input v-model="model.name" class="box-name" placeholder="请输入内容"></el-input>  
      </p>
      <el-button @click="addgetdata">提交</el-button>
    </div>
  </div>
</template>

<script>
import { addcategory ,Pcategory} from '../../api/index';
export default {
    data() {
        return {
            options: [],
            model:{},
            value:"",
        }
    },
    created () {
        Pcategory().then((res)=>{
            console.log(res);
            this.options=res.data
        });
    },
    methods: {
        addgetdata() {
            addcategory({parentId:this.model.id,categoryName:this.model.name}).then((res)=>{
              console.log(res);
                if(res.status===0){
                    alert(res.data)
                    this.$router.go(-1);
                }
            })
        }
    },
};
</script>

<style lang="scss" scoped>
.werapp {
  h1 {
    font-size: 50px;
  }
  .box-item {
    .box-name {
      width: 300px;
      padding: 10px 0;
    }
  }
}
</style>